<?php
/**
 *  -----------------母板---------------------------------------------
 *
 * @purpose: 对“通知”类型中子类型为x(XXXXXXXXXXXXXXXXX)的编码与解码文件
 * @author: Mandel Woo <wuzhijian@snda.com>

 * @memo: msg_notice_typex_encoder() 函数中传入的参数即是sendNotice时第三个参数data数组中的key,
		如sendNotice(xx,xx, array('a'=>,'b'=>,'c'=>)，则在该函数中可以用func_get_arg得到a,b,c三个参数。
		若data=null，则此处得不到参数。
		msg_notice_typex_encoder()的返回值长度不要大于500字符。

		msg_notice_typex_decoder函数中可得到以下一些参数：
		"id","receiverid","content","createTime","changeFlag","fmt"。
		其中content是msg_notice_typex_encoder函数的返回值。
		<code>
		$fields = array("id","receiverid","content","createTime","changeFlag","fmt");

		foreach($fields as $k => $v) {
			eval("\${$v}=func_get_arg($k);");
		}
		</code>
 */
require_once(dirname(__FILE__)."/../../../models/user/UCModUserInfo.php");


function msg_notice_typex_encoder() {
	#发送通知的方法：$o->sendNotice(str_type, receiver_sdid, array(key1, key2, ...))
	#观察这里的key1, key2与下行key1, key2的对应
	$fields = array("key1", "key2", ...);

	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}

	#该值即是下方decoder函数的content参数
	return serialize(array(
			"key1" => $key1,
			"key2" => $key2,
				...
				...
			));
}

function msg_notice_typex_decoder() {
	#这里不改动, begins
	$fields = array("id","receiverid","content","createTime","changeFlag","fmt");
	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}
	#这里不改动, ends

	#将encoder函数返回值解出来，即得到data[key1],data[key2],...
	$data     = unserialize($content);

	#业务逻辑
	...
	...


	#!!!输出处将不做html转义，须保证用户输入数据的安全
	if ($fmt == 'line') {
		return sprintf("%s接受了你的好友请求", $usr);

	} else if ($fmt == 'box') {
		return sprintf("%s接受了你的好友请求 %s", $usr, time_formater($createTime));

	} else {
		return '';
	}
}


